package com.yhb.yinsheng.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExecutionFlow {
    String id;
    String userId;
    String vipType;
    Type type;
    BigDecimal amount;
    String extendInfo;
    Date createTime;
    Status status;
    String cardId;
    BigDecimal commission; // 消费手续费
    BigDecimal remitFee; // 代付手续费
    Date updateTime;
    String orderId; // 对应通道订单号
    String retryId; // 重试后有个重试号
    String failReason; // 失败原因

    public enum Type {
        PAY,
        REMIT,
        ACTIVE_REMIT;
        public com.yhb.channel.dao.flow.ExecutionFlow.Type toCommonChannelType() {
            switch (this){
                case REMIT:
                    return com.yhb.channel.dao.flow.ExecutionFlow.Type.REMIT;
                case ACTIVE_REMIT:
                    return com.yhb.channel.dao.flow.ExecutionFlow.Type.ACTIVE_REMIT;
                case PAY:
                default:
                    return com.yhb.channel.dao.flow.ExecutionFlow.Type.PAY;
            }
        }
    }

    // PENDING ----> DONE
    //           |--> FAILED
    //           |--> RETRIED
    public enum Status {
        PENDING,
        DONE,
        FAILED,
        RETRIED;

        public com.yhb.channel.dao.flow.ExecutionFlow.FlowStatus toCommonChannelStatus() {
            switch (this) {
                case FAILED:
                    return com.yhb.channel.dao.flow.ExecutionFlow.FlowStatus.FAILED;
                case DONE:
                    return com.yhb.channel.dao.flow.ExecutionFlow.FlowStatus.SUCCEEDED;
                case RETRIED:
                    return com.yhb.channel.dao.flow.ExecutionFlow.FlowStatus.RETRIED;
                case PENDING:
                default:
                    return com.yhb.channel.dao.flow.ExecutionFlow.FlowStatus.INITIALIZED;
            }
        }


    }
}
